package com.ruoyi.web.controller.edh;

import java.util.List;
import java.util.Map;

import com.ruoyi.edh.domain.EdhRecommendation;
import com.ruoyi.edh.domain.vo.EdhRecommendationVo;
import com.ruoyi.edh.service.IEdhRecommendationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 易订货-首页轮播图Controller
 *
 * @author xxx
 * @date 2020-09-02
 */
@RestController
@RequestMapping("/edh/recommendation")
@Api(description = "易订货-首页轮播图")
public class EdhRecommendationController extends BaseController {
    @Autowired
    private IEdhRecommendationService edhRecommendationService;

    /**
     * 查询易订货-首页轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('system:recommendation:list')")
    @GetMapping("/list")
    @ApiOperation("易订货-首页轮播图列表")
    public TableDataInfo list(EdhRecommendation edhRecommendation) {
        startPage();
        List<EdhRecommendation> list = edhRecommendationService.selectEdhRecommendationList(edhRecommendation);
        return getDataTable(list);
    }

    /**
     * 查询首页轮播图
     *
     * @return
     */
    @GetMapping("/selectHomeRecommendation")
    @ApiOperation("易订货-首页轮播图接口")
    public AjaxResult selectHomeRecommendation() {
        List<Map<String, Object>> edhRecommendationVos = edhRecommendationService.selectHomeRecommendation();
        if (0 >= edhRecommendationVos.size()) {
            AjaxResult.error("查询失败轮播图数量小于1");
        }

        return AjaxResult.success("查询成功", edhRecommendationVos);
    }

    /**
     * 导出易订货-首页轮播图列表
     */
    @PreAuthorize("@ss.hasPermi('system:recommendation:export')")
    @Log(title = "易订货-首页轮播图", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ApiOperation("导出易订货-首页轮播图列表")
    public AjaxResult export(EdhRecommendation edhRecommendation) {
        List<EdhRecommendation> list = edhRecommendationService.selectEdhRecommendationList(edhRecommendation);
        ExcelUtil<EdhRecommendation> util = new ExcelUtil<EdhRecommendation>(EdhRecommendation.class);
        return util.exportExcel(list, "recommendation");
    }

    /**
     * 获取易订货-首页轮播图详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:recommendation:query')")
    @GetMapping("/{id}")
    @ApiOperation("获取易订货-首页轮播图详细信息")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(edhRecommendationService.selectEdhRecommendationById(id));
    }

    /**
     * 新增易订货-首页轮播图
     */
    @PreAuthorize("@ss.hasPermi('system:recommendation:add')")
    @Log(title = "易订货-首页轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增易订货-首页轮播图")
    public AjaxResult add(@RequestBody EdhRecommendation edhRecommendation) {
        return toAjax(edhRecommendationService.insertEdhRecommendation(edhRecommendation));
    }

    /**
     * 修改易订货-首页轮播图
     */
    @PreAuthorize("@ss.hasPermi('system:recommendation:edit')")
    @Log(title = "易订货-首页轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改易订货-首页轮播图")
    public AjaxResult edit(@RequestBody EdhRecommendation edhRecommendation) {
        return toAjax(edhRecommendationService.updateEdhRecommendation(edhRecommendation));
    }

    /**
     * 删除易订货-首页轮播图
     */
    @PreAuthorize("@ss.hasPermi('system:recommendation:remove')")
    @Log(title = "易订货-首页轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除易订货-首页轮播图")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(edhRecommendationService.deleteEdhRecommendationByIds(ids));
    }
}
